
//Eli Elder
//playcard
//makefile needs this
//unittest3: unittest3.c dominion.o rngs.o
//	gss -o unittest1 -g unittest3.c dominion.o rngs.o $(CFLAGS)


#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "rngs.h"

//set PRINTOUT to 0 to remove printfs out
#define PRINTOUT 1
#define ASSERTIVE 0
#define PRINTOUTASSERT 1

int checkGameOver(struct gameState *afterGameState){
    
    int provinceCount = 0;
    int estateCount;
    int duchyCount;
    int outofCards = 0;
    struct gameState beforeGameState;
    int returnVal;
    
    //copy so we can test if the Game card worked how we think it should
    memcpy(&beforeGameState, afterGameState, sizeof(struct gameState));
    //do the Game card
    returnVal = isGameOver(afterGameState);
    
#if (PRINTOUT == 1)
    //check supply count of just province
    if(beforeGameState.supplyCount[province] == 0){
	outofCards = 1; 
	printf("the province is at 0 game should be over\n");
    }
    //check supply count of just duchy
    if(beforeGameState.supplyCount[duchy] == 0){
	duchyCount = 0;
    }
    //check supply fof just estate
    if(beforeGameState.supplyCount[estate] == 0){
	estateCount = 0;
    }

    if(estateCount == 0 && duchyCount == 0 && provinceCount == 0){
	printf("all are out it should be over\n");
	outofCards = 1;
    }
#endif
#if (ASSERTIVE == 1)
    //assert the return was 0 if not all are otu
    assert(outofCards == returnVal);
#endif
#if (PRINTOUTASSERT == 1)
    //printout the numbers left
    printf("Provinces %d, estates %d, duchy's %d\n", beforeGameState.supplyCount[province], beforeGameState.supplyCount[estate], beforeGameState.supplyCount[duchy]);
#endif
    return 0;
 }

int main() {
    int provinceSupply;
    int estateSupply;
    int duchySupply; 
    
    int initialized;
    struct gameState theGameState;
    int player = 0;
    int kingCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, salvager};
    
    
    //this helps setup the random tests
    SelectStream(2);
    PutSeed(3);
   
    
    //small fixed tests that loop through EVERYTHING!!!!!!
    for(estateSupply = 2; estateSupply >= 0; estateSupply--){
	for(duchySupply = 2; duchySupply >= 0; duchySupply--){
	    for(provinceSupply = 2; provinceSupply >= 0; provinceSupply--){
		//setup and initialize the state (should do in random?)
		memset(&theGameState, 23, sizeof(struct gameState));
		initialized = initializeGame(player, kingCards, 1, &theGameState);
		//set supply things
		theGameState.supplyCount[province] = provinceSupply;
		theGameState.supplyCount[estate] = estateSupply;
		theGameState.supplyCount[duchy] = duchySupply;
		//do the test
		checkGameOver(&theGameState);
	    }
	}
    }

    printf("Note, if ASSERT and PRINTOUT are not flagged everything might look fine, but not be fine\n");
    return 0;
}
